import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_module/map/models/library_models.dart';
import 'package:flutter_module/system/log_util.dart';

import 'ni_map_method_id.dart';

class NIMarkerDispatcher {
  ///
  /// 在地图上添加marker
  /// [coordinate] 经纬度坐标 [pixel]屏幕像素 这两个都没有就用屏幕中心点
  /// [id] marker 标题 唯一标识字段
  /// [description] 描述信息
  Future<NIMarker?> addMarker(MethodChannel mapChannel,
      {NIGeoPoint? geoPoint,
      Offset? pixel,
      String? description = "",
      String id = ""}) async {
    if (geoPoint != null) {
      var result = await mapChannel.invokeMethod(
          NIMarkerMethodId.kMapAddMarkerMethod,
          {
            'longitude': geoPoint.longitude,
            'latitude': geoPoint.latitude,
            'description': description,
            'title': id,
          } as dynamic);
      return NIMarker.fromJson(result);
    } else if (pixel != null) {
      var result = await mapChannel.invokeMethod(
          NIMarkerMethodId.kMapAddMarkerMethod,
          {
            'xPixel': pixel.dx,
            'yPixel': pixel.dy,
            'description': description,
            'title': id,
          } as dynamic);
      return NIMarker.fromJson(result);
    } else {
      var result = await mapChannel.invokeMethod(
          NIMarkerMethodId.kMapAddMarkerMethod,
          {
            'description': description,
            'title': id,
          } as dynamic);
      return NIMarker.fromJson(result);
    }
  }

  Future<bool?> removeMarker(MethodChannel mapChannel, String id) async {
    return await mapChannel.invokeMethod(
        NIMarkerMethodId.kMapRemoveMarkerMethod, {"title": id}) as bool;
  }
}
